<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <script>
        // let xhr = new XMLHttpRequest();
        // xhr.open('GET', 'https://geoapi.qweather.com/v2/city/lookup?key=b79f6d08b72a4621b8dc4280f7cc864d&location=' + inp.value);
        // // xhr.open("GET","http://api.app.yami.byesame.com/prod/tag/prodTagList")
        // xhr.send();
        // xhr.onreadystatechange = function () {
        //     if (xhr.readyState == 4) {
        //         let a = JSON.parse(xhr.responseText);
        //         console.log(a);
        //         // 获取城市天气
        //         let xhrx = new XMLHttpRequest();
        //         xhrx.open('GET', 'https://devapi.qweather.com/v7/weather/now?key=b79f6d08b72a4621b8dc4280f7cc864d&location=' + a.location[0].id);
        //         xhrx.send();
        //         xhrx.onreadystatechange = function () {
        //             if (xhrx.readyState == 4) {
        //                 let b = JSON.parse(xhr.responseText);
        //                 console.log(b);
        //             }
        //         }
        //     }
        // }


        let p = new Promise((resolve, reject) => {
            let xhr = new XMLHttpRequest();
            xhr.open('GET', 'https://geoapi.qweather.com/v2/city/lookup?key=b79f6d08b72a4621b8dc4280f7cc864d&location=' + "青岛");
            // xhr.open("GET","http://api.app.yami.byesame.com/prod/tag/prodTagList")
            xhr.send();
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    let a = JSON.parse(xhr.responseText);
                    console.log(a);
                    resolve(a.location[0].id)
                }
            }
        })

        p.then((id) => {
            let xhrx = new XMLHttpRequest();
            xhrx.open('GET', 'https://devapi.qweather.com/v7/weather/now?key=b79f6d08b72a4621b8dc4280f7cc864d&location=' + id);
            xhrx.send();
            xhrx.onreadystatechange = function () {
                if (xhrx.readyState == 4) {
                    let b = JSON.parse(xhrx.responseText);
                    console.log(b);
                }
            }
        })

    </script>


</body>

</html>